package com.gtlab1207.br_security.services;

import com.gtlab1207.br_security.models.dao.AbacAttributeDao;
import com.gtlab1207.br_security.models.domain.AbacAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 业务层
 */
@Service
public class AbacAttributeService {

    @Autowired
    private AbacAttributeDao abacAttributeDao;

    /**
     * 查询所有信息
     * @param params
     * @return
     */
    public Map<String,Object> selectAbacAttribute(Map params){
        Map<String,Object> map = new HashMap<>();
        List<AbacAttribute> list = abacAttributeDao.selectAbacAttribute(params);
        map.put("data",list);
        map.put("total",list.size());
        return map;
    }

    /**
     * 添加信息
     * @param abacAttribute
     * @return
     */
    @Transactional
    public Integer insertAbacAttribute(AbacAttribute abacAttribute){
        Integer result = 0;
        if(abacAttribute!=null){
            result = abacAttributeDao.insertAbacAttribute(abacAttribute);
        }
        return result;
    }

    /**
     * 修改信息
     * @param abacAttribute
     * @return
     */
    @Transactional
    public Integer updateAbacAttribute(AbacAttribute abacAttribute){
        Integer result = 0;
        if(abacAttribute.getId()!=null){
            result = abacAttributeDao.updateAbacAttribute(abacAttribute);
        }
        return result;
    }



    /**
     * 删除信息
     * @param id
     * @return
     */
    @Transactional
    public Integer deleteAbacAttribute(Integer id){
        Integer result = 0;
        if(id!=null&&id>=0){
            result = abacAttributeDao.deleteAbacAttribute(id);
        }
        return result;
    }
}
